<template>
  <div class="header" >
       <!-- 折叠图片 -->
       <div class="collapse-btn" @click="collapseChange">
         <i class="el-icon-refresh"></i>
       </div>
       <div class="logo">隆道尔音乐网站后台管理系统</div>
       <div class="logo">免责声明：本网站所提供的信息,只供欣赏</div>
       <div class="header-right">
         <div class="btn-fullscreen" @click="openFullscreen(),closeFullscreen()">
           <el-tooltip :content='fullscreen?`取消全屏`:`全屏`' placement="bottom">
                <i class="el-icon-setting"></i>
           </el-tooltip>
         </div>
         <div class="user-avator">
           <img src="../assets/img/user.jpg" />
         </div>
         <el-dropdown class="user-name" trigger="click" @command="handleCommand">
            <span class="el-dropdown-link">
              {{userName}}
              <i class="el-icon-caret-bottom"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
         </el-dropdown>
       </div>
  </div>
</template>

<script>
import bus from "../assets/js/bus";
export default {
  
  data(){
    return {
      collapse: false,
      fullscreen: false,
    }
  },
  computed:{
    userName(){
      return localStorage.getItem("userName");
    }
  },
  methods:{
    //侧边栏
    collapseChange(){
      this.collapse = !this.collapse;
      bus.$emit('collapse',this.collapse);
    },
    //全屏事件
    openFullscreen() {     /* Open fullscreen */
      var elem = document.documentElement;
      if (elem.requestFullscreen) { 
        elem.requestFullscreen();
      } else if (elem.mozRequestFullScreen) {    /* Firefox */
        elem.mozRequestFullScreen();
      } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
        elem.webkitRequestFullscreen();
      } else if (elem.msRequestFullscreen) {     /* IE/Edge */
        elem.msRequestFullscreen();
      }
    },
    closeFullscreen() {   /* Close fullscreen */
      if (document.fullscreenElement) { 
        document.exitFullscreen();    
      }else if (document.mozCancelFullScreen) {  /* Firefox */
        document.mozCancelFullScreen();
      } else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
        document.webkitExitFullscreen();
      } else if (document.msExitFullscreen) {     /* IE/Edge */
        document.msExitFullscreen();
      }
    },
    handleCommand(command){
      if(command == "logout"){
        localStorage.removeItem("userName");
        this.$router.push("/");
      }
    },   
  },
  
}

</script>

<style scoped>
.header{
  position: relative;
  background-color: #2e5c74;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  font-size: 22px;
  font-family: Microsoft JhengHei;
  color: #ffffff;
}
.collapse-btn{
  float: left;
  padding: 0 21px;
  cursor: pointer;
  line-height: 70px;
}
.header .logo{
  float: left;
  line-height: 70px;
  padding-left: 200px;
}
.header-right{
  float: right;
  padding-right: 50px;
  display: flex;
  height: 70px;
  align-items: center;
}
.btn-fullscreen{
  transform: rotate(45deg);
  margin-right: 5px;
  font-size: 24px;
}
.user-avator{
  margin-left: 20px;
}
.user-avator img{
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.user-name{
  margin-left: 10px;

}

.el-dropdown-link{
  color: #ffffff;
  cursor: pointer;
}
</style>